# -*- coding: utf-8 -*-
from openpyxl import load_workbook
import long_run
import read_configuration
import os

import three_sport
import two_sport


def get_excel_date():
    path_excel = os.getcwd()
    xlsx_path_list = read_configuration.path_excel_read()
    for xlsx_name in xlsx_path_list:
        if "xlsx" in xlsx_name:
            xlsx_path = (path_excel + '/' + '表格附件' + '/' + xlsx_name.strip('\n'))
            # print(xlsx_path)
            wb = load_workbook(xlsx_path)
            sheet_now_list = wb.sheetnames
            # print(sheet_now_list)
            # print(path_excel)
            # with open("这是个txt", 'r') as file:
            #     date = file.read()
            #     print(date)
            for sheet_now in sheet_now_list:
                ws = wb[sheet_now]  # 获取工作表
                n = 5  # 第三行开始读
                # print(sheet_now)

                for row in ws.iter_rows(min_row=5):
                    # print(ws.max_row)
                    student_name = ws.cell(n, 2).value  # 学生名字
                    student_gender = ws.cell(n, 3).value  # 学生性别
                    student_test1_name = ws.cell(n, 5).value  # 学生第一类项目
                    student_test1 = ws.cell(n, 6).value  # 学生项目一成绩
                    student_test1_score = ws.cell(n, 7).value  # 学生项目一分数
                    student_test2_name = ws.cell(n, 8).value  # 第二类项目
                    student_test2_grade = ws.cell(n, 9).value  # 学生项目二成绩
                    student_test2_score = ws.cell(n, 10).value  # 学生项目二得分
                    student_test3_name = ws.cell(n, 11).value  # 项目三名称
                    student_test3_grade = ws.cell(n, 12).value  # 学生项目3成绩
                    student_test3_score = ws.cell(n, 13).value  # 学生项目3得分
                    student_cell = n  # 当前行
                    """判断三大类项目，第一类三选一，第二类七选一，第三类六选一"""
                    if student_test1_name == "1000米" or student_test1_name == 1000 or student_test1_name == "1000":
                        "处理第一类800/1000"
                        if student_name is not None and student_gender is not None:
                            # 男1000米跑
                            one_result = long_run.calculate_boys_1000m_score(student_test1, student_cell, xlsx_name,
                                                                             sheet_now)
                    elif student_test1_name == 800 or student_test1_name == "800" or student_test1_name == "800米":
                        # 女生800
                        one_result = long_run.calculate_girls_1000m_score(student_test1, student_cell, xlsx_name,
                                                                          sheet_now)
                        # ws.cell(column=7, row=student_cell, value=one_result)  # 写入800。1000成绩
                    # else:
                    #     print(f"【{xlsx_name}】工作簿,【{sheet_now}】工作表,第【{student_cell}】行,【{student_name}】,信息有误")
                    elif student_test1_name == "游泳" or student_test1_name == "200米游泳":
                        """处理游泳"""
                        pass
                    elif student_test1_name == "跳绳" or student_test1_name == "4分钟跳绳" or student_test1_name == "4min跳绳":
                        pass

                    if student_test2_name == "100米跑" or student_test2_name == 100 or student_test2_name == "100":
                        """处理第二类100米跑"""
                        two_result = 0
                    elif student_test2_name == "跳绳" or student_test2_name == "1分钟跳绳" or student_test2_name == "1min跳绳":
                        """处理第二类跳绳"""
                        two_result = two_sport.two_rope_skipping(student_test2_grade, student_cell, xlsx_name, sheet_now
                                                                 , student_gender)
                    elif student_test2_name == "实心球" or student_test2_name == "投实心球" or student_test2_name == "投掷实心球":
                        """处理实心球"""
                        two_result = two_sport.two_solid_ball(student_test2_grade, student_cell, xlsx_name, sheet_now
                                                              , student_gender)
                    elif student_test2_name == "踢毽子" or student_test2_name == "毽子" or student_test2_name == "一分钟踢毽子":
                        """处理毽子"""
                        two_result = two_sport.two_shuttlecock(student_test2_grade, student_cell, xlsx_name, sheet_now
                                                               , student_gender)
                    elif student_test2_name == "蛙跳" or student_test2_name == "二级蛙跳" or student_test2_name == "二级蛙":
                        """处理蛙跳"""
                        two_result = 0
                    elif student_test2_name == "10X4折返跑" or student_test2_name == "折返跑" or student_test2_name == "10X4" \
                            or student_test2_name == "折返":
                        """折返"""
                        two_result = 0
                    elif student_test2_name == "游泳" or student_test2_name == "50米游泳" or student_test2_name == "50" or \
                            student_test2_name == 50:
                        """游泳"""
                        two_result = float(two_sport.two_50_swim(student_test2_grade, student_cell, xlsx_name,
                                                                 sheet_now, student_gender))
                    """处理第三类"""
                    if student_test3_name == "足球":
                        """足球"""
                        three_result = three_sport.three_football(student_test3_grade, student_cell, xlsx_name,
                                                                  sheet_now, student_gender)
                    elif student_test3_name == "篮球":
                        """篮球"""
                        three_result = three_sport.three_basketball(student_test3_grade, student_cell, xlsx_name,
                                                                    sheet_now, student_gender)
                    elif student_test3_name == "排球球":
                        """排球"""
                        three_result = three_sport.three_volleyball(student_test3_grade, student_cell, xlsx_name,
                                                                    sheet_now, student_gender)
                    elif student_test3_name == "网球":
                        """网球"""
                        three_result = three_sport.three_tennis(student_test3_grade, student_cell, xlsx_name,
                                                                sheet_now, student_gender)
                    elif student_test3_name == "羽毛球":
                        """羽毛球"""
                        three_result = three_sport.three_badminton(student_test3_grade, student_cell, xlsx_name,
                                                                   sheet_now, student_gender)
                    elif student_test3_name == "乒乓球":
                        """乒乓球"""
                        three_result = three_sport.three_ping_pong(student_test3_grade, student_cell, xlsx_name,
                                                                   sheet_now, student_gender)
                    if student_test1_name is not None:
                        ws.cell(column=7, row=student_cell, value=one_result)  # 写入第一类项目成绩
                    if student_test2_name is not None:
                        ws.cell(column=10, row=student_cell, value=two_result)
                    if student_test3_name is not None:
                        ws.cell(column=13, row=student_cell, value=three_result)
                    n += 1
            wb.save(xlsx_path)
        else:
            # 非xlsx文件pass
            pass
